local Hanjian = fk.CreateSkill {
    name = "Hanjian",
    anim_type = "defensive",
    tags = {Skill.Compulsory},
}

Fk:loadTranslationTable{
  ["Hanjian"] = "罕见",
  ["$Hanjian1"] = "罕见三段突",
  [":Hanjian"] = "锁定技，当其他角色对你造成伤害后，其随机获得一个技能直到本轮结束。",
  ["#Hanjian_skill"] = "%from 的【罕见】被触发，%to 获得了技能【%arg】",
}

-- 当其他角色对你造成伤害后触发
Hanjian:addEffect(fk.Damage, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(Hanjian.name) and target ~= player and data.to == player and data.from
  end,
  
  on_use = function(self, event, target, player, data)
    local room = player.room
    local kingdom_skills = {}

    local round = room.logic:getCurrentEvent():findParent(GameEvent.Round)
    if round ~= nil then
        for name, general in pairs(Fk.generals) do
            for _, skill_name in ipairs(general:getSkillNameList()) do
                if not skill_name:startsWith("#") and not skill_name:endsWith("&") and not data.from:hasSkill(skill_name) then
                    table.insertIfNeed(kingdom_skills, skill_name)
                end
            end
        end
        local skill = kingdom_skills[math.random(1, #kingdom_skills)]
        room:handleAddLoseSkills(data.from, skill, nil)
        round:addCleaner(function()
          room:handleAddLoseSkills(data.from, "-" .. skill, nil)
        end)
    end
  end,
})


return Hanjian 